package com.controller;

import com.github.pagehelper.PageInfo;
import com.pojo.Item;
import com.service.ItemService;
import com.vo.ChargeItemVo;
import com.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/*import org.springframework.web.bind.annotation.RestController;*/

@Controller
@RequestMapping("/Item")
public class ItemController {
    @Resource
    private ItemService itemService;
    @RequestMapping("/toItem")
    public String toItem(){
        return "ChargeSettings/ChargeItem";
    }
    @ResponseBody
    @RequestMapping("/selectAllItem")
    public Result selectAllItem(ChargeItemVo chargeItemVo){
        PageInfo<Item> pageInfo = itemService.selectItemByCondition(chargeItemVo);
        return Result.success(pageInfo);
    }
    @ResponseBody
    @RequestMapping("/updateItem")
    public Result updateItem(Item item){
        try {
            int i = itemService.updateItem(item);
            return Result.success("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.success("修改失败");
        }

    }
    @ResponseBody
    @RequestMapping("/deleteItem")
    public Result deleteItem(Integer id){
        try {
            int i = itemService.deleteById(id);
            return Result.success("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.success("删除失败");
        }
    }
    @ResponseBody
    @RequestMapping("/addItem")
    public Result addItem(Item item){
        try {
            int i = itemService.addItem(item);
            return Result.success("添加成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.success("添加失败");
        }
    }
    @ResponseBody
    @RequestMapping("/selectItemOther")
    public Result selectItemOther(){
        List<Item> itemList = itemService.selectItemOther();
        return Result.success(itemList);
    }
    @ResponseBody
    @RequestMapping("/selectGuDingItem")
    public Result selectGuDingItem(){
        List<Item> itemList = itemService.selectAllGuDingItem();
        return Result.success(itemList);
    }
}
